package me.zhengjie.pm.issuerelated.domain;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import me.zhengjie.pm.projectbase.domain.ProjectBase;
import me.zhengjie.pm.projectissue.domain.ProjectIssue;

import javax.persistence.*;
import javax.validation.constraints.*;
import java.io.Serializable;

/**
* @author yuxj
* @date 2020-05-02
*/
@Entity
@Data
@Table(name="issue_related")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class IssueRelated implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;

    /** 原问题ID */
    @Column(name = "issue_id",nullable = false)
    @NotNull
    private Integer issueId;

    @ManyToOne
    @JoinColumn(name = "issue_id",insertable = false, updatable = false, nullable=true)
    private ProjectIssue projectIssue;

    /** 关联型号 */
    @Column(name = "related_type")
    private String relatedType;

    /** 关联项目ID */
    @Column(name = "related_project")
    private Integer relatedProject;

    @ManyToOne
    @JoinColumn(name = "related_project",insertable = false, updatable = false, nullable=true)
    private ProjectBase projectBase;

    public void copy(IssueRelated source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}